﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TraceInspector.Data.Server;
using System.Collections.ObjectModel;
using AutoMapper;

namespace TraceInspector.Application
{
    public class UIDataProvider : IUIDataProvider
    {
        ServerEntities _serverEntities;
        ObservableCollection<Model.Inspection> _inspections;

        public UIDataProvider()
        {
            _serverEntities = new ServerEntities();
            //Mapper.CreateMap(typeof(Data.Server.inspect), typeof(Model.Inspection));
        }

        #region Члены IUIDataProvider

        public ObservableCollection<Model.Inspection> GetInspections()
        {
            return _inspections ?? (_inspections = new ObservableCollection<Model.Inspection>(_serverEntities.inspects.ToList().Select(c => InspectionTranslator.Instance.CreateModel(c))));
            //return _inspections ?? (_inspections = new ObservableCollection<Model.Inspection>(_serverEntities.inspects.ToList().Select(c => Mapper.Map <Model.Inspection> (c))));
        }

        public void UpdateInspection(Model.Inspection inspection)
        {
            InspectionTranslator.Instance.UpdateDto(_serverEntities.inspects.Single(insp => insp.id == inspection.Id), inspection);
            _serverEntities.SaveChanges(); 
        }

        public void ReadInspectionObjects(Model.Inspection inspection)
        {
            
        }

        public void ReadInspectionReports(Model.Inspection inspection)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
